package com.wwwc.admin.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.SQLException;

import com.wwwc.admin.web.database.*;
import com.wwwc.util.web.*;

public class adminUserAccountManagerBean {

    public StringBuffer getManagerBar (String call_path, String account_cb, String storage_payment_cb, String storage_cb, String action) {
	StringBuffer sbf = new StringBuffer("");
	sbf.append("<TABLE border=1  cellSpacing=0 cellPadding=5>");
	sbf.append("<TR>");
	if(action != null && action.equals(account_cb)) {
	    sbf.append("<TD>Account</TD>");
	}
	else {
	    sbf.append("<TD><A href="+call_path+"?aid="+account_cb+">Account</A></TD>");
	}

	if(action != null && action.equals(storage_payment_cb)) {
	    sbf.append("<TD>Storage Payment</TD>");
	}
	else {
	    sbf.append("<TD><A href="+call_path+"?aid="+storage_payment_cb+">Storage Payment</A></TD>");
	}

	if(action != null && action.equals(storage_cb)) {
	    sbf.append("<TD>Storage</TD>");
	}
	else {
	    sbf.append("<TD><A href="+call_path+"?aid="+storage_cb+">Storage</A></TD>");
	}
	sbf.append("</TR>");
	sbf.append("</TABLE>");
	return sbf;
    }

    public StringBuffer processStoragePayment(HttpServletRequest request, String call_path, String call_back) {
	StringBuffer sbf = new StringBuffer();
	String error = null;
	String submit    = request.getParameter("process_payment");
	String user_id   = null;
	String item_name = null;
	String item_id   = null;
	String quantity  = null;
	String price     = null;
	String duration  = null;
	String storage_size = null;
	String total = null;

	if(user_id == null) {
	    user_id = "";
	}
	if(error != null) {
	    sbf.append("<img src=/images/star.gif><I>"+error+"</I><BR>");
	}
	sbf.append("<FORM method=post action="+call_path+">");
	sbf.append("<TABLE border='0'  cellSpacing='0' cellPadding='2' style='font-size: 10pt'>");
	sbf.append("<TR>");
	sbf.append("<TD>Username</TD>");
	sbf.append("<TD><input type=text name=user_id value='"+user_id+"' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Item name</TD>");
	sbf.append("<TD><input type=text name=item_name value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Item ID</TD>");
	sbf.append("<TD><input type=text name=item_id value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Quantity</TD>");
	sbf.append("<TD><input type=text name=quantity value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Price</TD>");
	sbf.append("<TD><input type=text name=price value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Duration</TD>");
	sbf.append("<TD><input type=text name=duration value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Storage Size</TD>");
	sbf.append("<TD><input type=text name=storage_size value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Total</TD>");
	sbf.append("<TD><input type=text name=total value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");
	/*
	sbf.append("<TR>");
	sbf.append("<TD>Process By</TD>");
	sbf.append("<TD><input type=text name=processer value='"+user_naem+"' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");
	*/
	sbf.append("<TR>");
	sbf.append("<TD colspan=2 align=center><BR><BR><input type=submit name=process_order value=Add style='font-size: 8pt'>");
	sbf.append("<input type=reset value=Reset style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("</TABLE>");

	sbf.append("<input type=hidden name=aid value="+call_back+">");
	sbf.append("</FORM>");
	//sbf.append(DebugBean.getInputs("UserAccountMBean", request));
	return sbf;
    }

    public StringBuffer addUserStorage(HttpServletRequest request, String call_path, String call_back) {
	StringBuffer sbf = new StringBuffer();
	String error = null;
	String submit    = request.getParameter("process_order");
	String user_id   = null;
	String item_name = null;
	String item_id   = null;
	String quantity  = null;
	String price     = null;
	String duration  = null;
	String storage_size = null;
	String total = null;

	if(user_id == null) {
	    user_id = "";
	}
	if(error != null) {
	    sbf.append("<img src=/images/star.gif><I>"+error+"</I><BR>");
	}
	sbf.append("<FORM method=post action="+call_path+">");
	sbf.append("<TABLE border='0'  cellSpacing='0' cellPadding='2' style='font-size: 10pt'>");
	sbf.append("<TR>");
	sbf.append("<TD>Username</TD>");
	sbf.append("<TD><input type=text name=user_id value='"+user_id+"' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Item name</TD>");
	sbf.append("<TD><input type=text name=item_name value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Item ID</TD>");
	sbf.append("<TD><input type=text name=item_id value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Quantity</TD>");
	sbf.append("<TD><input type=text name=quantity value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Price</TD>");
	sbf.append("<TD><input type=text name=price value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Duration</TD>");
	sbf.append("<TD><input type=text name=duration value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Storage Size</TD>");
	sbf.append("<TD><input type=text name=storage_size value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("<TR>");
	sbf.append("<TD>Total</TD>");
	sbf.append("<TD><input type=text name=total value='' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");
	/*
	sbf.append("<TR>");
	sbf.append("<TD>Process By</TD>");
	sbf.append("<TD><input type=text name=processer value='"+user_naem+"' style='font-size: 8pt'></TD>");
	sbf.append("</TR>");
	*/
	sbf.append("<TR>");
	sbf.append("<TD colspan=2 align=center><BR><BR><input type=submit name=process_order value=Add style='font-size: 8pt'>");
	sbf.append("<input type=reset value=Reset style='font-size: 8pt'></TD>");
	sbf.append("</TR>");

	sbf.append("</TABLE>");

	sbf.append("<input type=hidden name=aid value="+call_back+">");
	sbf.append("</FORM>");
	//sbf.append(DebugBean.getInputs("UserAccountMBean", request));
	return sbf;
    }

    public StringBuffer listDatabases(ResourceBundle SystemInfo, String call_path, int display) {
	StringBuffer sbf = new StringBuffer();
	String databases =  SystemInfo.getString("3wcenter.databases");
	if(display ==1) {
	    sbf.append("\n<TABLE border='1'  cellSpacing='0' cellPadding='2' style='font-size: 10pt' width='100%'>");
	    sbf.append("\n<TR><TD align='center' colspan='3'><B>Avaiable Databases</B></TD></TR>");
	    sbf.append("\n<TR><TD>Database</TD><TD>URL</TD><TD>Driver</TD></TR>");

	    StringTokenizer tokens = new StringTokenizer(databases, ",");
	    String temp = null;

	    while (tokens.hasMoreTokens()) {
		temp = tokens.nextToken();
		sbf.append("\n<TR><TD>"+temp+"</TD>");
		sbf.append("\n<TD>"+SystemInfo.getString("3wcenter.database."+temp+".db_name")+"</TD>");
		sbf.append("\n<TD>"+SystemInfo.getString("3wcenter.database."+temp+".driver_name")+"</TD>");
		sbf.append("\n</TR>");
	    }
	    sbf.append("\n</TABLE>");
	}

	if(display ==2) {
	    sbf.append("\n<TABLE border='0'  cellSpacing='0' cellPadding='2' style='font-size: 10pt'>");
	    sbf.append("\n<TR><TD><B>Databases</B></TD></TR>");

	    StringTokenizer tokens = new StringTokenizer(databases, ",");
	    String temp = null;

	    while (tokens.hasMoreTokens()) {
		temp = tokens.nextToken();
		sbf.append("\n<TR><TD><A href="+call_path+"?database="+temp+"&action=list_table>"+temp+"</A></TD></TR>");
	    }
	    sbf.append("\n</TABLE>");
	}
	return sbf;
    }
}
